home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Trading on the Edge
/
Trading On The Edge - CD-ROM Toolkit (Wayzata Technology)(2031)(1994).bin
/
pc
/
mac_file
/
software
/
nn_prepr
/
finpre2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-30
|
67KB
|
2,175 lines
/* 22:00 24-Sep-92 (finpre.c) Financial Pre-processing Driver */
#include "fin.h" /* includes stdio.h, etc. */
#include "fincmd.h"
#include <time.h>
#define NLDS /* include commands for non-linear dynamical systems */
#undef CORRDIMORG /* do not use original correlation dim code */
/************************************************************************
* Copyright(C) 1992 High-Tech Communications. *
* 103 Buckskin Court, Sewickley, PA 15143 *
* *
* Written by Casimir C. Klimasauskas *
* *
* All rights reserved. No part of this program may be reproduced, *
* stored in a retrieval system, or tramsmitted, in any form or by any *
* means, electronic, mechanical, photocopying, recording or otherwise *
* without the prior written permission of the copyright owner, *
* High-Tech Communications. *
* *
* These programs are supplied on an "as-is" basis with no warranties *
* of fitness or operability, either express or implied. *
* *
************************************************************************
20-Sep-92 cck
Added Non-Linear Dynamical Systems routines to menus
*/
/************************************************************************
* *
* Financial Data Pre-processor *
* *
************************************************************************
*/
typedef struct _field { /* field in master data-base */
float *FDataFP; /* data */
char *FTickCP; /* ticker */
char *FSymCP; /* label */
short FFlagI; /* flags */
#define FF_DB 0x01 /* field from data-base */
#define FF_DRV 0x02 /* field is derived */
#define FF_INTRP 0x04 /* field has been interpolated */
} FIELD;
typedef struct _fdes { /* field descriptor */
FIELD *FFieldTP; /* pointer to field */
char *FTickCP; /* ticker */
char *FSymCP; /* label */
short FOffI; /* offset */
short FFlagI; /* flags */
#define FD_TICK 0x01 /* ticker is present */
#define FD_SYM 0x02 /* symbol is present */
#define FD_OFF 0x04 /* offset is present */
#define FD_FOUND 0x10 /* field found in field table */
int FldXI; /* field index if found */
} FDES;
/* Global storage for the data-base & transformations. The
* date is kept in a separate array (FDateLP). The array
* for the date is dynamically allocated when the size of the
* data-base is known. Field vectors are dynamically allocated
* when needed. The dictionary is allocated separately at the
* very start of the program. The purpose of these procedures is
* to try to keep from fragmenting memory any more than necessary.
*/
FIELD FldTA[MAXTF+1] = {0}; /* master field array */
long *FDateLP = {0}; /* pointer to master date array */
int FieldsI = {0}; /* # of fields in data-base */
int FVecI = {0}; /* # of rows in data-base */
/* Command data storage. The following items are the result of
* parsing various commands. The data is stored in this area
* and used by the global interface routines.
*/
char XFieldCA[80] = {"xfield"}; /* raw x-field descriptor */
FDES XFieldT = {0}; /* parsed x-field descriptor */
char YFieldCA[80] = {"yfield"}; /* raw y-field descriptor */
FDES YFieldT = {0}; /* parsed y-field descriptor */
FILE *LogFP = {0}; /* log file */
char LogFile[120] = {"none"}; /* logging file */
char DBFile[120] = {"data.db"}; /* data base file */
char DBStrDateCA[20]= {"00/00/00"}; /* start date */
char DBEndDateCA[20]= {"12/31/99"}; /* end date */
long DBStrDateL = {0x19000000L};/* start date */
long DBEndDateL = {0x19991231L};/* end date */
char OutFile[120] = {"data.nna"}; /* training file */
char OFStrDateCA[20]= {"00/00/00"}; /* start date */
char OFEndDateCA[20]= {"12/31/99"}; /* end date */
long OFStrDateL = {0x0}; /* start date */
long OFEndDateL = {0x19991231L};/* end date */
char SaveFile[120] = {"save.db"}; /* save data-base */
char SVStrDateCA[20]= {"00/00/00"}; /* start date */
char SVEndDateCA[20]= {"12/31/99"}; /* end date */
long SVStrDateL = {0x0}; /* start date */
long SVEndDateL = {0x19991231L};/* end date */
double MinScaleD = {-1.}; /* minimum scale */
double MaxScaleD = { 1.}; /* maximum scale */
double ExpFactorD = {0.3}; /* exponential decay factor */
int SpanI = {5}; /* # of days to span */
int SmoothI = {5}; /* # of days to smooth */
/* Global data for analysis section */
double ShortLowD = {-1.0}; /* low limit for short position */
double ShortHighD = {-0.2}; /* high limit for short position */
double LongLowD = { 0.2}; /* low limit for long position */
double LongHighD = { 1.0}; /* high limit for long position */
double CapitalD = { 10000. }; /* starting capital */
char PrFldCP[40] = { "" }; /* price field */
float *PriceFP = {0}; /* price data itself */
char NetFileCA[120] = {"untitled.nnr"}; /* ".nnr" file for analysis */
char NetDateCA[20] = {"00/00/00"}; /* start date for network */
long NetDateL = {0}; /* start date for network */
float *NetValFP[10] = {0}; /* network data */
int NetFieldsI = {0}; /* # of fields in network */
char AnlDateCA[20] = {"00/00/00"}; /* analysis start date */
long AnlDateL = {0}; /* start of analysis date */
int AnlFldXI = {0}; /* index of field to analyze */
#ifdef NLDS
char NFieldCA[80] = {"field"}; /* raw NLDS analysis field */
FDES NFieldT = {0}; /* parsed field */
char NStrDateCA[20] = {"00/00/00"}; /* start date */
long NStrDateL = {0}; /* binary start date */
char NEndDateCA[20] = {"12/31/99"}; /* end date */
long NEndDateL = {0x19991231L};/* binary end date */
int StartWinI = {5}; /* start window size */
int DeltaWinI = {5}; /* delta window size */
int IterationsI = {50}; /* number of iterations to perform */
int DerivativeI = {1}; /* derivative of series */
int EmbeddingI = {3}; /* embedding dimension */
int StartDimI = {2}; /* start dimension */
int EndDimI = {6}; /* end dimension */
int tauI = {1}; /* phase space shift */
int EvolveI = {3}; /* minimum steps for evolution */
int LagMinimumI = {10}; /* minimum lag between points */
double dtD = {0.1}; /* change in radius */
double radiusD = {0.05}; /* initial radius */
double NMinScaleD = {0.1}; /* minimum value for scale */
double NMaxScaleD = {2.5}; /* maximum value for scale */
char PrintFileCA[80]= {"untitled.prn"}; /* printer output file */
#define PRT_TEXT 0 /* formatted text output */
#define PRT_COMMA 1 /* lotus style output */
#define PRT_TAB 2 /* excel style output */
int PrintTypeI = {PRT_TEXT}; /* mode of printed output */
FILE *PrintFileFP = {0}; /* file pointer for output file */
long PrintFilePosL = {0}; /* file position when opened */
char TypeFileCA[80] = {"untitled.prn"}; /* type the print file */
int NFieldFlagI = {0}; /* valid field flag */
float *NFldDataFP = {0}; /* pointer to the data */
int NFldStrXI = {0}; /* start index */
int NFldLengthI = {0}; /* # of items to use */
#endif
/************************************************************************
* *
* ClearDBI() - Clear out a loaded Data-base *
* *
************************************************************************
*/
int ClearDBI() /* clear out fields allocated for a data-base */
{
int wxI; /* work index */
FIELD *fldP; /* field pointer */
for( wxI = 0; wxI < ASof(FldTA); wxI++ ) {
fldP = &FldTA[wxI];
if ( fldP->FDataFP != (float *)0 ) free( (void *)fldP->FDataFP );
fldP->FDataFP = (float *)0;
fldP->FTickCP = (char *)0;
fldP->FSymCP = (char *)0;
fldP->FFlagI = 0;
}
FDateLP = (long *)0; /* NOTE: allocated as "FldTA[0].FDataFP" */
FVecI = FieldsI = 0;
for( wxI = 0; wxI < ASof(NetValFP); wxI++ ) {
if ( NetValFP[wxI] != (float *)0 ) free( (void *)NetValFP[wxI] );
NetValFP[wxI] = (float *)0;
}
NetFieldsI = 0;
PriceFP = (float *)0;
strcpy( PrFldCP, "" );
DCClearV(); /* Clear & re-initialize the dictionary */
return( 0 );
}
/************************************************************************
* *
* LoadDBI() - Load a Data-base *
* *
************************************************************************
*/
int LoadDBI( fnCP, SDateL, EDateL ) /* load a data-base */
char *fnCP; /* file name of data-base */
long SDateL; /* start date */
long EDateL; /* end date */
{
FILE *fp; /* file pointer to data-base */
int nfldI; /* # of fields */
int cfldI; /* current field index */
long nlinL; /* # of lines */
int ncfldI; /* # of current fields */
long linL; /* length of longest line */
long clinL; /* length of current line */
unsigned linU; /* unsigned line length */
int chI; /* work character */
int nhdrI; /* # of items in the header */
int rcI; /* return code */
int stateI; /* current state */
int rowI; /* current row of input data */
FIELD *fldP; /* field pointer */
char *DBbufCP; /* data-base buffer */
char *sp, *ap; /* work character pointer */
char *dp; /* date pointer */
long dL; /* date */
char buf[80]; /* message & work buffer */
/* --- pre-set up --- */
if ( SDateL == 0 && EDateL == 0 ) {
EDateL = 0x19991231L;
} else if ( SDateL > EDateL ) {
linL = SDateL; SDateL = EDateL; EDateL = linL;
}
/* --- Open the File --- */
rcI = 0; /* return code */
DBbufCP = (char *)0; /* no data-base buffer yet */
fp = (FILE *)0; /* file is closed */
ClearDBI(); /* free any existing memory */
if ( (fp = fopen( fnCP, "rb" )) == (FILE *)0 ) {
sprintf( buf, "Could not open data-base input file <%s>\n", fnCP );
goto Error;
}
/* --- Count the number of fields & lines in the data-base --- */
nfldI = ncfldI = 0;
nlinL = 1L;
linL = clinL = 0L;
stateI = 0;
dp = &buf[0];
while( (chI = getc(fp)) != EOF ) {
clinL++; /* current line length */
if ( chI > ' ' && stateI <= 1 ) {
stateI = 1;
if ( dp < &buf[sizeof(buf)-16] )
*dp++ = chI;
} else if ( stateI == 1 ) {
*dp = 0;
stateI = 2;
}
switch( chI ) {
case '\n':
if ( clinL > linL ) linL = clinL; /* longest line */
clinL = 0L;
if ( stateI == 2 ) {
dL = Date2BinL( buf );
if ( SDateL <= dL && dL <= EDateL ) {
nlinL++;
if ( ncfldI > nfldI ) nfldI = ncfldI;
}
}
ncfldI = 0;
stateI = 0;
dp = &buf[0];
break;
case '\t':
ncfldI++;
break;
}
}
/* --- digest information about lines & fields --- */
fseek( fp, 0L, 0 ); /* rewind input file */
if ( linL > 32000L ) { /* check for maximum line size */
sprintf( buf, "Longest line is too long for program (%ld)\n", linL );
goto Error;
}
linU = linL+16; /* allocate the input line buffer */
if ( (DBbufCP = (char *)malloc( linU )) == (char *)0 ) {
sprintf( buf, "Could not allocate line buffer size (%ld)\n", linL );
goto Error;
}
/* --- Read in the data-base --- */
if ( (nlinL * sizeof(float)) > MAXVECSIZE ) {
sprintf( buf, "Too much storage (%ld/%ld) required per item\n",
nlinL*sizeof(float), (long)MAXVECSIZE );
goto Error;
}
linU = nlinL * sizeof(float);
stateI = 0;
rowI = 0;
while( (sp = fgets( DBbufCP, linU, fp )) != (char *)0 ) {
while( *sp && *sp <= ' ' ) sp++;
if ( *sp == '!' || *sp == 0 ) continue;
sp = DBbufCP; /* reset line pointer for tab intercept */
switch( stateI ) {
case 0: /* first line of header */
for( cfldI = 0; *sp != 0 && cfldI < ASof(FldTA); cfldI++ ) {
fldP = &FldTA[cfldI]; /* current field */
for( ap=sp; *ap && *ap != '\t'; ) ap++; /* skip field */
chI = *ap; /* save char */
*ap = 0; /* null terminate */
fldP->FTickCP = DCDupCP( DCLwrPkCP(sp) );
fldP->FFlagI = FF_DB; /* data-base field */
if ( (fldP->FDataFP = (float *)malloc( linU )) == (float *)0 ) {
sprintf( buf,
"Could not allocate space (%u) for vector (%d)\n",
linU, cfldI );
goto Error;
}
if ( cfldI == 0 ) FDateLP = (long *)fldP->FDataFP;
if ( chI == '\t' ) ap++; /* skip tab */
sp = ap;
}
FieldsI = cfldI;
stateI = 1;
break;
case 1: /* second line of header */
for( cfldI = 0; cfldI < FieldsI; cfldI++ ) {
fldP = &FldTA[cfldI]; /* current field */
for( ap=sp; *ap && *ap != '\t'; ) ap++; /* skip field */
chI = *ap; /* save char */
*ap = 0; /* null terminate */
fldP->FSymCP = DCDupCP( DCLwrPkCP(sp) );/* label */
if ( chI == '\t' ) ap++; /* skip tab */
sp = ap;
}
stateI = 2;
break;
case 2: /* data */
if ( rowI > nlinL ) break; /* too many lines */
for( cfldI = 0; cfldI < FieldsI; cfldI++ ) {
fldP = &FldTA[cfldI]; /* current field */
for( ap=sp; *ap && *ap != '\t'; ) ap++; /* skip field */
chI = *ap; /* save char */
*ap = 0; /* null terminate */
if ( cfldI ) /* numeric data */
fldP->FDataFP[rowI] = strtod( sp, (char **)0 );
else FDateLP[rowI] = Date2BinL( sp ); /* date */
if ( chI == '\t' ) ap++; /* skip tab */
sp = ap;
}
if ( SDateL <= FDateLP[rowI] && FDateLP[rowI] <= EDateL )
rowI++; /* ok to load this row */
break;
}
}
FVecI = rowI;
Done:
if ( DBbufCP != (char *)0 ) free( (void *)DBbufCP );
if ( fp != (FILE *)0 ) fclose( fp );
if ( rcI == 0 ) {
fprintf( stdout, "%d records read from database <%s>\n",
FVecI, fnCP );
DBStrDateL = FDateLP[0];
DBEndDateL = FDateLP[FVecI-1];
strcpy( DBStrDateCA, Date2StrCP( DBStrDateL ) );
strcpy( DBEndDateCA, Date2StrCP( DBEndDateL ) );
OFStrDateL = DBStrDateL;
OFEndDateL = DBEndDateL;
strcpy( OFStrDateCA, DBStrDateCA );
strcpy( OFEndDateCA, DBEndDateCA );
SVStrDateL = DBStrDateL;
SVEndDateL = DBEndDateL;
strcpy( SVStrDateCA, DBStrDateCA );
strcpy( SVEndDateCA, DBEndDateCA );
NetDateL = DBStrDateL;
strcpy( NetDateCA, DBStrDateCA );
AnlDateL = DBStrDateL;
strcpy( AnlDateCA, DBStrDateCA );
#ifdef NLDS
NFieldFlagI = 0;
strcpy( &NFieldCA[0], "field" );
NStrDateL = DBStrDateL;
NEndDateL = DBEndDateL;
strcpy( NStrDateCA, DBStrDateCA );
strcpy( NEndDateCA, DBEndDateCA );
#endif
}
return( rcI );
Error:
MsgER( buf );
rcI = -1;
goto Done;
}
/************************************************************************
* *
* SearchDBI() - Search Data-base to see if symbol is there *
* *
************************************************************************
*/
int SearchDBI( tCP, fCP, ModeI ) /* search data-base */
char *tCP; /* ticker pointer */
char *fCP; /* label pointer */
int ModeI; /* mode bits to look for */
{
int wxI; /* work index */
FIELD *p; /* pointer to field */
/* --- Search Data-base for symbol --- */
if ( tCP == (char *)0 || *tCP == 0 ) return( -1 );
if ( fCP == (char *)0 || *fCP == 0 ) fCP = (char *)0;
for( wxI = 0; wxI < ASof(FldTA); wxI++ ) {
p = &FldTA[wxI];
if ( (p->FFlagI & ModeI) != 0 && strcmp( p->FTickCP, tCP ) == 0 ) {
if ( fCP == (char *)0 || strcmp( p->FSymCP, fCP ) == 0 )
return( wxI );
}
}
return( -1 );
}
/************************************************************************
* *
* FieldParseI() - Parse a field definition *
* *
************************************************************************
ticker.label[+/-offset]
rc: -1 = syntax error
0 = success
fdTP-> results. If not FD_FOUND, pointers
should be looked up in the dictionary.
*/
int FieldParseI( fdTP, fdCP ) /* parse a field */
FDES *fdTP; /* pointer to field data structure */
char *fdCP; /* pointer to field string */
{
FIELD *fTP; /* field structure itself */
char *tCP, *fCP; /* ticker & field pointers */
char *oCP; /* offset */
char *sp; /* work pointer */
char *dp; /* destination pointer */
int c; /* work char */
int OffsetI; /* offset for computations */
int wxI; /* work offset */
static char wbf[80]; /* work buffer */
/* --- Convert to lower case & remove spaces --- */
for( sp = fdCP, dp = &wbf[0]; (c = *sp)!=0; sp++ ) {
if ( 'A' <= c && c <= 'Z' ) c -= 'A'-'a';
if ( c > ' ' ) *dp++ = c;
}
*dp = 0;
if ( wbf[0] == 0 ) {
Error: return( -1 ); /* syntax error */
}
tCP = fCP = oCP = (char *)0; /* nothing yet */
for( sp = &wbf[0]; *sp; sp++ ) {
switch( *sp ) {
default:
if ( tCP != (char *)0 ) goto Error;
tCP = sp;
while( *sp > ' ' && *sp != '.' && *sp != '(' && *sp != '[' &&
*sp != ')' && *sp != ']' ) sp++;
sp--;
break;
case '.':
if ( tCP == (char *)0 || fCP != (char *)0 ) goto Error;
*sp++ = 0;
fCP = sp;
while( *sp && *sp != '(' && *sp != '[' && *sp != '.' ) sp++;
sp--;
break;
case '[': case '(':
if ( tCP == (char *)0 || oCP != (char *)0 ) goto Error;
*sp++ = 0; /* null terminate prior item */
oCP = sp;
if ( *sp == '+' || *sp == '-' ) sp++;
OffsetI = 0;
while( '0' <= *sp && *sp <= '9' ) { sp++; OffsetI++; }
if ( OffsetI == 0 || (*sp != ')' && *sp != ']') ) goto Error;
*sp = 0;
break;
case '+': case '-':
case ']': case ')':
goto Error;
}
}
if ( tCP == (char *)0 ) goto Error;
if ( fCP != (char *)0 && *fCP == 0 ) goto Error;
OffsetI = (oCP == (char *)0)? 0:atoi(oCP);
/* --- Search Data-base for symbol --- */
fdTP->FldXI = 0;
fdTP->FFlagI = FD_TICK;
if ( (wxI = SearchDBI( tCP, fCP, FF_DB )) >= 0 ) {
fdTP->FldXI = wxI;
fdTP->FFieldTP = &FldTA[wxI];
fdTP->FFlagI |= FD_FOUND;
tCP = FldTA[wxI].FTickCP;
if ( fCP ) fCP = FldTA[wxI].FSymCP;
}
fdTP->FTickCP = tCP;
fdTP->FSymCP = fCP;
fdTP->FOffI = OffsetI;
if ( fCP != (char *)0 ) fdTP->FFlagI |= FD_SYM;
if ( oCP != (char *)0 ) fdTP->FFlagI |= FD_OFF;
return( 0 );
}
/************************************************************************
* *
* FieldBuildI() - Build a new field in the data-base *
* *
************************************************************************
return: >= 0, field index
< 0, error
*/
int FieldBuildI( tCP, fCP, trnCP ) /* build a field */
char *tCP; /* ticker of input field */
char *fCP; /* label of input field */
char *trnCP; /* transformation */
{
int cI; /* column index */
int wI; /* work int */
FIELD *p; /* pointer to field */
float *pF; /* float pointer */
char buf[80]; /* work buf */
if ( (cI = FieldsI) >= ASof(FldTA) )
return( MsgER( "Maximum allowable fields in data-base already" ) );
p = &FldTA[cI];
wI = FVecI * sizeof(float);
if ( (pF = (float *)malloc( (unsigned)wI )) == (float *)0 )
return( MsgER( "Could not allocate space for data vector" ) );
FieldsI++;
p->FDataFP = pF;
p->FFlagI = FF_DRV;
strcpy( buf, tCP );
strcat( buf, "_" );
strcat( buf, fCP );
p->FTickCP = DCDupCP( buf );
sprintf( buf, "%s_%d", trnCP, cI );
p->FSymCP = DCDupCP( buf );
for( wI = 0; wI < FVecI; wI++ ) *pF++ = 0.0;
return( cI );
}
/************************************************************************
* *
* Action Routines *
* *
************************************************************************
*/
/* --- General purpose error messages --- */
MustLoadDBI() { MsgER( "Must load data-base first" ); return(-1); }
/* --- Basic Action Commands --- */
/* --- CMDLoad() ---
* Load a Data-Base into memory
*/
INPUT LISTLoad[] = {
ISTR( DBFile, IO_FNM ),
ISTR( DBStrDateCA, IO_DTE|IO_OPT ),
ISTR( DBEndDateCA, IO_DTE|IO_OPT ),
INUL
};
int CMDLoad( cmdP, cntL, eFP ) /* load a data-base file */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
int rcI; /* return code */
DBEndDateL = cntL < 3? 0x19991231L:Date2BinL(DBEndDateCA);
DBStrDateL = cntL < 2? 0x19000101L:Date2BinL(DBStrDateCA);
rcI = LoadDBI( DBFile, DBStrDateL, DBEndDateL );
return( rcI );
}
/* --- CMDInterp() ---
* Interpolate zero data-items in each column.
*/
int CMDInterp( cmdP, cntL, eFP )
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
int cI, rI; /* column index, row index */
int aI; /* alt index */
float aF, bF, iF; /* start / end float values */
FIELD *p; /* field pointer */
float *pF; /* data pointer */
if ( FieldsI <= 0 ) return( MustLoadDBI() );
for( cI = 1; cI < FieldsI; cI++ ) {
p = &FldTA[cI];
if ( (p->FFlagI & FF_DB) == 0 ||
(p->FFlagI & FF_INTRP) != 0 ) continue;
pF = p->FDataFP;
for( rI = 0; rI < FVecI; rI++ ) {
if ( pF[rI] == 0.0 ) {
for( aI = rI; aI < FVecI; aI++ )
/* --- find non-zero val --- */
if ( pF[aI] != 0.0 ) break;
if ( rI == 0 && aI < FVecI ) {
/* --- zeros at start of data --- */
bF = pF[aI];
while( rI < aI ) pF[rI++] = bF;
} else if ( rI > 0 && aI >= FVecI ) {
/* --- zeros at end of data --- */
aF = pF[rI-1];
while( rI < aI ) pF[rI++] = aF;
} else if ( rI > 0 && aI < FVecI ) {
/* --- zeros in middle of data --- */
aF = pF[rI-1]; /* rI=0 caught in first case */
bF = pF[aI];
iF = (bF - aF) / (aI - rI + 1);
for( aF += iF; rI < aI; rI++, aF += iF ) pF[rI] = aF;
} else break; /* --- all zeros --- */
}
}
p->FFlagI |= FF_INTRP;
}
return( 0 );
}
/* --- CMDScale() ---
* Scale ALL data into the specified range
*/
INPUT LISTScale[] = {
IVAL( MinScaleD, IO_FLT|IO_OPT, FMT_FLT2, 0 ),
IVAL( MaxScaleD, IO_FLT|IO_OPT, FMT_FLT2, 0 ),
INUL
};
int CMDScale( cmdP, cntL, eFP )
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
int cI, rI; /* column index, row index */
FIELD *p; /* pointer to field item */
float *pF; /* pointer to data */
double MinD, MaxD; /* work variables */
double wD; /* work double */
double ScD, OfD; /* scale & offset for this column */
if ( FieldsI <= 0 ) return( MustLoadDBI() );
for( cI = 1; cI < FieldsI; cI++ ) {
p = &FldTA[cI];
if ( (p->FFlagI & FF_DRV) == 0 )
continue; /* only scale derived fields */
pF = p->FDataFP;
MinD = MaxD = pF[0];
for( pF++, rI = 1; rI < FVecI; rI++, pF++ ) {
wD = *pF;
if ( wD < MinD ) MinD = wD;
if ( wD > MaxD ) MaxD = wD;
}
if ( MinD == MaxD ) {
ScD = OfD = 0.0;
} else {
ScD = (MaxScaleD - MinScaleD) / (MaxD - MinD);
OfD = (MinScaleD - MinD * ScD);
if ( fabs(ScD-1.0) < 1.e-3 && fabs(OfD) < 1.e-3 )
continue; /* already scaled */
}
for( pF = p->FDataFP, rI = 0; rI < FVecI; rI++, pF++ )
*pF = ScD * (*pF) + OfD;
}
return( 0 );
}
/* --- Format a Field of Data with minimum trailing zeros --- */
static char *FmtFltCP( fmtCP, vD ) /* format a floating point number */
char *fmtCP; /* format */
double vD; /* double value */
{
char *sp; /* work pointer */
static char buf[80]={0}; /* work buffer */
sprintf( buf, fmtCP, vD ); /* format the number */
for( sp = &buf[0]; *sp; sp++ ) /* check for decimal points */
if ( *sp == '.' ) break;
if ( *sp != 0 ) {
for( sp = &buf[strlen(buf)-1]; sp > &buf[0]; sp-- )
if ( *sp != '0' ) break;
if ( *sp == '.' ) sp--;
sp[1] = 0;
}
return( &buf[0] );
}
/* --- Generate an output file --- */
int WriteFile( fnCP, StrDL, EndDL, ModeI ) /* create an output file */
char *fnCP; /* name of file to create */
long StrDL, EndDL; /* start & end dates */
int ModeI; /* types of items to include */
{
FILE *ofFP=0; /* output file pointer */
int cI, rI; /* column index, row index */
int ffI; /* first field flag */
FIELD *p; /* pointer to field item */
float *pF; /* pointer to data */
double wD; /* work double */
long ctL; /* current time */
char *sp, *dp; /* work pointers */
char buf[80]; /* date buffer */
if ( FieldsI <= 0 ) return( MustLoadDBI() );
/* --- Sanity check: Is there anything to do? --- */
if ( StrDL > EndDL ) {
ctL = StrDL; StrDL = EndDL; EndDL = ctL;
}
for( rI = 0; rI < FVecI; rI++ )
if ( StrDL <= FDateLP[rI] && FDateLP[rI] <= EndDL )
break; /* found something in range */
if ( rI >= FVecI )
return( MsgER( "Nothing in date range specified" ) );
for( cI = 1; cI < FieldsI; cI++ )
if ( (FldTA[cI].FFlagI & ModeI) != 0 ) break;
if ( cI >= FieldsI )
return( MsgER( "Nothing to write" ) );
/* --- Open the file --- */
if ( (ofFP = fopen( fnCP, "w" )) == (FILE *)0 )
return( MsgER( "Could not open output file" ) );
/* --- Write out the data itself --- */
time( &ctL );
for( dp=buf, sp=asctime(localtime(&ctL)); *sp; sp++ )
if ( *sp >= ' ' ) *dp++ = *sp;
*dp = 0;
fprintf( ofFP, "!%s (%s)\n", buf, fnCP );
for( ffI = 0, cI = 0; cI < FieldsI; cI++ ) {
p = &FldTA[cI];
if ( (p->FFlagI & ModeI) != 0 ) {
fputs( ffI?"\t":((ModeI & FF_DB)==0?"!":""), ofFP );
fputs( p->FTickCP, ofFP );
ffI++;
}
}
fputs( "\n", ofFP );
for( ffI = 0, cI = 0; cI < FieldsI; cI++ ) {
p = &FldTA[cI];
if ( (p->FFlagI & ModeI) != 0 ) {
fputs( ffI?"\t":((ModeI & FF_DB)==0?"!":""), ofFP );
fputs( p->FSymCP, ofFP );
ffI++;
}
}
fputs( "\n", ofFP );
for( ; rI < FVecI; rI++ ) {
if ( FDateLP[rI] > EndDL ) break;
for( ffI = 0, cI = 0; cI < FieldsI; cI++ ) {
p = &FldTA[cI];
if ( (p->FFlagI & ModeI) != 0 ) {
wD = p->FDataFP[rI];
fputs( ffI?"\t":"", ofFP );
if ( cI == 0 ) {
fputs( Date2StrCP( FDateLP[rI] ), ofFP );
} else {
fputs( FmtFltCP( "%.4f", wD ), ofFP );
}
ffI++;
}
}
fputs( "\n", ofFP );
}
fclose( ofFP );
return( 0 );
}
/* --- Create a "transformed" data file --- */
INPUT LISTTrans[] = {
ISTR( OutFile, IO_FNM ),
ISTR( OFStrDateCA, IO_DTE|IO_OPT),
ISTR( OFEndDateCA, IO_DTE|IO_OPT),
INUL
};
int CMDTrans( cmdP, cntL, eFP )
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
int rcI; /* return code */
OFStrDateL = Date2BinL( OFStrDateCA );
OFEndDateL = Date2BinL( OFEndDateCA );
rcI = WriteFile( OutFile, OFStrDateL, OFEndDateL, FF_DRV );
return( rcI );
}
/* --- Save output of data-base in a new file --- */
INPUT LISTSave[] = {
ISTR( SaveFile, IO_FNM ),
ISTR( SVStrDateCA, IO_DTE|IO_OPT),
ISTR( SVEndDateCA, IO_DTE|IO_OPT),
INUL
};
int CMDSave( cmdP, cntL, eFP )
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
int rcI; /* return code */
if ( cntL > 1 ) {
SVStrDateL = Date2BinL( SVStrDateCA );
SVEndDateL = Date2BinL( SVEndDateCA );
} else {
SVStrDateL = 0L;
SVEndDateL = 0x19991231L;
}
rcI = WriteFile( SaveFile, SVStrDateL, SVEndDateL, FF_DRV|FF_DB );
return( rcI );
}
/* --- CMDLog() ---
* Change / set the output log file
*/
int CMDLog( cmdP, cntL, eFP )
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
FILE *fp; /* work file pointer */
if ( strcmp( "none", LogFile ) == 0 ) {
if ( LogFP != (FILE *)0 ) fclose( LogFP );
LogFP = (FILE *)0;
return( 0 );
}
if ( (fp = fopen( LogFile, "w" )) == (FILE *)0 )
return( MsgER( "Could not open new log file. Using old one." ) );
if ( LogFP ) fclose( LogFP );
LogFP = fp;
return( 0 );
}
int CheckPointLogFile() /* check point the log file */
{ /* --- Temporarily close log file to preserve anything in it --- */
if ( LogFP ) {
fflush( LogFP );
fclose( LogFP );
LogFP = fopen( LogFile, "a" );
return( 1 );
}
return( 0 );
}
/* --- CMDDict() ---
* Print out the dictionary of data in memory
*/
int CMDDict( cmdP, cntL, eFP )
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
FIELD *p; /* pointer to field item */
int cI; /* column */
char buf[80]; /* work buffer */
if ( FieldsI <= 1 )
return( MustLoadDBI() );
sprintf( buf, "--- Current Dictionary ---\n" );
fputs( buf, eFP );
if ( LogFP ) fputs( buf, LogFP );
for( cI = 1; cI < FieldsI; cI++ ) {
p = &FldTA[cI];
sprintf( buf, " %s.%s", p->FTickCP, p->FSymCP );
switch( p->FFlagI & (FF_DB | FF_DRV | FF_INTRP) ) {
case FF_DB: strcat( buf, " (data)" ); break;
case FF_DB|FF_INTRP: strcat( buf, " (data,interpolated)" ); break;
case FF_DRV: strcat( buf, " (transform)" );
}
strcat( buf, "\n" );
fputs( buf, eFP );
if ( LogFP ) fputs( buf, LogFP );
}
fflush( eFP );
if ( LogFP ) fflush( LogFP );
return( 0 );
}
/* --- CMDQuit() ---
* Terminate the program.
*/
int QuitI = {0}; /* quit flag */
int CMDQuit( cmdP, cntL, eFP )
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
QuitI = 1;
return( 0 );
}
/* --- DoCommandsI() --- Execute commands from the command line
* until "quit" is encountered. Provide for recursive calls
* from other routines to switch to alternate command tables &
* sub-functions.
*/
int DoCommandsI( ct, PromptSP ) /* execute commands */
CMD *ct; /* command table */
char *PromptSP; /* prompt */
{
int rc; /* return code */
char *sp; /* string pointer */
char *wsp; /* work string pointer */
char buf[80]; /* work buffer */
int QuitSaveI; /* save old quit flag */
QuitSaveI = QuitI;
for( QuitI = 0; QuitI == 0 ;) {
fputs( PromptSP, stdout );
fputs( "> ", stdout );
fflush( stdout );
sp = fgets( buf, sizeof(buf), stdin );
wsp = sp;
if ( LogFP ) {
fprintf( LogFP, "%s> %s", PromptSP, buf );
rc = ParseLineI( &wsp, &ct[0], LogFP, 1 ); /* syntax check */
wsp = sp;
CheckPointLogFile();
}
rc = ParseLineI( &wsp, &ct[0], stdout, 1 ); /* syntax check */
if ( rc == 0 ) {
wsp = sp;
rc = ParseLineI( &wsp, &ct[0], stdout, 0 );
CheckPointLogFile();
}
}
QuitI = QuitSaveI;
return( 0 );
}
/* --- Transformations --- */
INPUT LISTFldDay[] = { /* field,days */
ISTR( XFieldCA, IO_FLD ),
IVAL( SpanI, IO_INT,FMT_INTU, 0 ),
INUL
};
INPUT LISTFFDay[] = { /* field,field,days */
ISTR( XFieldCA, IO_FLD ),
ISTR( YFieldCA, IO_FLD ),
IVAL( SpanI, IO_INT,FMT_INTU, 0 ),
INUL
};
INPUT LISTOFFDay[] = { /* [field],field,days */
ISTR( XFieldCA, IO_FLD|IO_OPT ),
ISTR( YFieldCA, IO_FLD ),
IVAL( SpanI, IO_INT,FMT_INTU, 0 ),
INUL
};
INPUT LISTStoch[] = { /* field,days[,smooth] */
ISTR( XFieldCA, IO_FLD ),
IVAL( SpanI, IO_INT,FMT_INTU, 0 ),
IVAL( SmoothI, IO_INT|IO_OPT,FMT_INTU, 0 ),
INUL
};
int FieldSetupI( ppsF, ppdF, plenI, trnCP )
float **ppsF; /* pointer to source data pointer */
float **ppdF; /* pointer to dest data pointer */
int *plenI; /* pointer to length */
char *trnCP; /* pointer to transform type */
{
float *psF, *pdF; /* source / destination data */
int dfXI; /* destination field index */
int lenI; /* work length */
int offI; /* offset */
int wI; /* absolute offset */
if ( FieldParseI( &XFieldT, XFieldCA ) )
return( MsgER( "Could not parse field" ) );
if ( (XFieldT.FFlagI & FD_FOUND) == 0 )
return( MsgER( "Field specified could not be found" ) );
offI = XFieldT.FOffI;
wI = offI < 0? (-offI):(offI);
if ( (FVecI - wI) <= 2 )
return( MsgER( "Field offset is too big for data" ) );
psF = XFieldT.FFieldTP->FDataFP;
dfXI = FieldBuildI( XFieldT.FTickCP, XFieldT.FSymCP, trnCP );
if ( dfXI < 0 ) return( dfXI );
pdF = FldTA[dfXI].FDataFP;
lenI = FVecI - wI; /* adjust length */
if ( offI > 0 ) psF += wI;
else if ( offI < 0 ) pdF += wI;
*ppsF = psF;
*ppdF = pdF;
*plenI = lenI;
return( 0 );
}
int FieldSetup2I( pps1F, pps2F, ppdF, plenI, trnCP, Opt1I )
float **pps1F; /* pointer to first source data pointer */
float **pps2F; /* pointer to second source data pointer */
float **ppdF; /* pointer to dest data pointer */
int *plenI; /* pointer to length */
char *trnCP; /* pointer to transform type */
int Opt1I; /* =1, first arg is NOT there */
{
float *ps1F,*ps2F,*pdF; /* source / destination data */
int dfXI; /* destination field index */
int lenI; /* work length */
int off1I, off2I; /* offset */
int offdI; /* offset of destination */
int wI; /* work integer */
/* --- Parse First Field --- */
if ( Opt1I ) {
ps1F = (float *)0;
off1I = 0;
} else {
if ( FieldParseI( &XFieldT, XFieldCA ) )
return( MsgER( "Could not parse field" ) );
if ( (XFieldT.FFlagI & FD_FOUND) == 0 )
return( MsgER( "Field specified could not be found" ) );
off1I = XFieldT.FOffI;
wI = off1I < 0? (-off1I):(off1I);
if ( (FVecI - wI) <= 2 )
return( MsgER( "Field offset 1 is too big for data" ) );
ps1F = XFieldT.FFieldTP->FDataFP;
}
/* --- Parse Second Field --- */
if ( FieldParseI( &YFieldT, YFieldCA ) )
return( MsgER( "Could not parse second field" ) );
if ( (YFieldT.FFlagI & FD_FOUND) == 0 )
return( MsgER( "Second field could not be found" ) );
off2I = YFieldT.FOffI;
wI = off2I < 0? (-off2I):(off2I);
if ( (FVecI - wI) <= 2 )
return( MsgER( "Field offset 2 is too big for data" ) );
ps2F = YFieldT.FFieldTP->FDataFP;
/* --- Build result field --- */
dfXI = FieldBuildI( YFieldT.FTickCP, YFieldT.FSymCP, trnCP );
if ( dfXI < 0 ) return( dfXI );
pdF = FldTA[dfXI].FDataFP;
lenI = FVecI;
/* --- adjust the pointers as required --- */
if ( ps1F == (float *)0 ) {
wI = (off2I < 0? (-off2I):(off2I));
lenI -= wI; /* adjust length */
if ( off2I > 0 ) ps2F += wI;
else if ( off2I < 0 ) pdF += wI;
} else {
if ( off1I <= off2I && off1I < 0 ) offdI = (-off1I);
else if ( off1I > off2I && off2I < 0 ) offdI = (-off2I);
else offdI = 0;
off1I += offdI;
off2I += offdI;
wI = offdI;
if ( wI < off1I ) wI = off1I;
if ( wI < off2I ) wI = off2I; /* wI is largest offset */
lenI = FVecI - wI; /* adjusted length */
ps1F += off1I; /* adjusted pointers */
ps2F += off2I;
pdF += offdI;
}
*pps1F = ps1F;
*pps2F = ps2F;
*ppdF = pdF;
*plenI = lenI;
return( 0 );
}
int CMDMovAvg( cmdP, cntL, eFP ) /* compute moving average */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
int rcI; /* work return code */
float *psF, *pdF; /* source / destination data */
int lenI; /* work length */
if ( FieldSetupI( &psF, &pdF, &lenI, "movavg" ) < 0 )
return( -1 );
MovAvgV( pdF, psF, lenI, SpanI );
return( 0 );
}
int CMDRSI( cmdP, cntL, eFP ) /* relative strength index */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
float *psF, *pdF; /* source / destination data */
int lenI; /* work length */
if ( FieldSetupI( &psF, &pdF, &lenI, "rsi" ) < 0 )
return( -1 );
RSIV( pdF, psF, lenI, SpanI );
return( 0 );
}
int CMDStoch( cmdP, cntL, eFP ) /* stochastic */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
float *psF, *pdF; /* source / destination data */
int lenI; /* work length */
if ( FieldSetupI( &psF, &pdF, &lenI, "stoch" ) < 0 )
return( -1 );
StochasticV( pdF, psF, lenI, SpanI, SmoothI );
return( 0 );
}
int CMDVol( cmdP, cntL, eFP ) /* volatility */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
float *psF, *pdF; /* source / destination data */
int lenI; /* work length */
if ( FieldSetupI( &psF, &pdF, &lenI, "vol" ) < 0 )
return( -1 );
VolatilityV( pdF, psF, lenI, SpanI );
return( 0 );
}
int CMDHLVol( cmdP, cntL, eFP ) /* high/low volatility */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
float *psF, *pdF; /* source / destination data */
float *qsF; /* alt source data */
int lenI; /* work length */
if ( FieldSetup2I( &psF, &qsF, &pdF, &lenI, "hlvol", 0 ) < 0 )
return( -1 );
HighLowVolatilityV( pdF, psF, qsF, lenI, SpanI );
return( 0 );
}
int CMDSlope( cmdP, cntL, eFP ) /* regression slope */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
float *psF, *pdF; /* source / destination data */
float *qsF; /* alt source data */
int lenI; /* work length */
int Opt1I; /* optional input parameter */
Opt1I = cntL < 3? 1:0;
if ( FieldSetup2I( &psF, &qsF, &pdF, &lenI, "slope", Opt1I ) < 0 )
return( -1 );
SlidingRegressionV( pdF, (float *)0, psF, qsF, lenI, SpanI );
return( 0 );
}
int CMDInter( cmdP, cntL, eFP ) /* regression intercept */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
float *psF, *pdF; /* source / destination data */
float *qsF; /* alt source data */
int lenI; /* work length */
int Opt1I; /* optional input parameter */
Opt1I = cntL < 3? 1:0;
if ( FieldSetup2I( &psF, &qsF, &pdF, &lenI, "intercept", Opt1I ) < 0 )
return( -1 );
SlidingRegressionV( (float *)0, pdF, psF, qsF, lenI, SpanI );
return( 0 );
}
int CMDCorr( cmdP, cntL, eFP ) /* rolling correlation */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
float *psF, *pdF; /* source / destination data */
float *qsF; /* alt source data */
int lenI; /* work length */
if ( FieldSetup2I( &psF, &qsF, &pdF, &lenI, "corr", 0 ) < 0 )
return( -1 );
RollingCorrelationV( pdF, psF, qsF, lenI, SpanI );
return( 0 );
}
int CMDRaw( cmdP, cntL, eFP ) /* raw data (typically offset) */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
float *psF, *pdF; /* source / destination data */
int lenI; /* work length */
if ( FieldSetupI( &psF, &pdF, &lenI, "raw" ) < 0 )
return( -1 );
for( ; lenI; lenI-- ) *pdF++ = *psF++;
return( 0 );
}
/* --- Analysis Section --- */
#define RPT_SUMMARY 0x0001 /* summary */
#define RPT_TRANS 0x0002 /* detail transactions */
int ReportFI = {RPT_SUMMARY|RPT_TRANS}; /* report flags */
LIT LITReport[] = {
{ "summary", RPT_SUMMARY },
{ "detail", RPT_TRANS },
{ "all", RPT_SUMMARY|RPT_TRANS },
{ 0 }
};
INPUT LISTLong[] = {
IVAL( LongLowD, IO_FLT,FMT_FLT2, 0 ),
IVAL( LongHighD, IO_FLT,FMT_FLT2, 0 ),
INUL
};
INPUT LISTShort[] = {
IVAL( ShortLowD, IO_FLT,FMT_FLT2, 0 ),
IVAL( ShortHighD, IO_FLT,FMT_FLT2, 0 ),
INUL
};
INPUT LISTNet[] = {
ISTR( NetFileCA, IO_FNM ),
ISTR( NetDateCA, IO_DTE ),
INUL
};
int CMDNet( cmdP, cntL, eFP ) /* load network data */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
FILE *fp; /* file pointer */
int cI, rI; /* column, row indicies */
float *pF; /* float pointer */
long dL; /* work date */
int dxI; /* date index */
double vD; /* work double */
char *sp, *ep; /* work string pointers */
char buf[1024]; /* max data buffer */
dL = Date2BinL( NetDateCA ); /* convert network data date */
for( rI = 0; rI < FVecI; rI++ )
if ( dL == FDateLP[rI] ) break;
if ( rI >= FVecI )
return( MsgER( "Specified date is not in data-base" ) );
dxI = rI;
/* --- see that file is there --- */
if ( (fp = fopen( NetFileCA, "r" )) == (FILE *)0 )
return( MsgER( "Network data file does not exist" ) );
/* --- check for memory & allocate if requried --- */
if ( NetValFP[0] == (float *)0 ) {
/* --- must allocate space (deallocated when DB loaded --- */
for( cI = 0; cI < ASof(NetValFP); cI++ ) {
NetValFP[cI] = (float *)malloc( FVecI*sizeof(float) );
if ( NetValFP[cI] == (float *)0 )
return(MsgER("Insufficient memory to allocate network area" ));
}
}
/* --- Clear out memory --- */
NetFieldsI = 0;
for( cI = 0; cI < ASof(NetValFP); cI++ ) {
pF = NetValFP[rI];
for( cI = 0; cI < FVecI; cI++, pF++ ) *pF = 0.0;
}
AnlFldXI = 0; /* start with first column */
strcpy( AnlDateCA, NetDateCA ); /* use network date */
/* --- Read file into memory --- */
rI = dxI;
while( (sp = fgets( buf, sizeof(buf), fp )) != (char *)0 ) {
while( *sp && *sp <= ' ' ) sp++; /* skip leading spaces */
if ( *sp == 0 || *sp == '!' ) continue;
for( cI = 0; cI < ASof(NetValFP); cI++ ) {
while( *sp && *sp <= ' ' ) sp++; /* skip leading spaces */
if ( *sp == 0 || *sp == '!' ) break;
vD = strtod( sp, &ep ); /* try conversion */
if ( sp == ep ) break; /* error */
NetValFP[cI][rI] = vD; /* store data */
sp = ep;
}
if ( cI > NetFieldsI ) NetFieldsI = cI;
rI++;
if ( rI >= FVecI ) break;
}
fclose( fp );
return( 0 );
}
int CMDPrice( cmdP, cntL, eFP ) /* Check that price field is valid */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
FDES PriceFD; /* field descriptor */
if ( FieldParseI( &PriceFD, PrFldCP ) != 0 ) {
MsgER( "Invalid price field" );
PriceErr:
PriceFP = (float *)0;
strcpy( PrFldCP, "" );
return( -1 );
}
if ( (PriceFD.FFlagI & FD_FOUND) == 0 ) {
MsgER( "Price field was not found in data-base" );
goto PriceErr;
}
PriceFP = PriceFD.FFieldTP->FDataFP;
return( 0 );
}
INPUT LISTAnal[] = {
ISTR( AnlDateCA, IO_DTE|IO_OPT ),
IVAL( AnlFldXI, IO_INT|IO_OPT, FMT_INTU, 0 ),
INUL
};
int CMDAnal( cmdP, cntL, eFP ) /* perform analysis of data */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
long dL; /* date to start analysis at */
int fldXI; /* column to analyze */
int rI; /* row to start at */
int nI; /* # of items to analyze */
int rcI=0; /* return code */
int *wBSSigIP=0; /* buy/sell signal array */
float *wEqFP=0; /* equity */
float *wPLFP=0; /* P&L */
float *NSigFP; /* neural network signal */
if ( FieldsI == 0 )
return( MsgER( "Must load data-base prior to analysis" ) );
if ( PriceFP == (float *)0 )
return( MsgER( "Must specify price field prior to analysis" ) );
if ( NetFieldsI == 0 )
return( MsgER( "Must load network data prior to analysis" ) );
fldXI = (cntL>1? AnlFldXI:0);
if ( fldXI >= NetFieldsI )
return( MsgER( "Requested column is not in network data\n" ) );
dL = Date2BinL( AnlDateCA );
for( rI = 0; rI < FVecI; rI++ )
if ( dL <= FDateLP[rI] ) break;
if ( rI >= FVecI )
return( MsgER( "Requested date is past end of data-base" ) );
/* --- allocate temporary storage --- */
nI = FVecI - rI;
wBSSigIP = (int *) malloc( nI * sizeof(int) );
wEqFP = (float *)malloc( nI * sizeof(float) );
wPLFP = (float *)malloc( nI * sizeof(float) );
if ( wBSSigIP == (int *)0 || wEqFP == (float *)0 || wPLFP == (float *)0 ) {
MsgER( "Could not allocate temporary memory required for analysis" );
rcI = -1;
goto Done;
}
NetEvalV( NetValFP[fldXI]+rI, PriceFP+rI, FDateLP+rI,
wBSSigIP, wEqFP, wPLFP,
nI, (ReportFI&RPT_TRANS)?1:0, eFP,
ShortLowD, ShortHighD, LongLowD, LongHighD, CapitalD );
if ( LogFP != (FILE *)0 )
NetEvalV( NetValFP[fldXI]+rI, PriceFP+rI, FDateLP+rI,
wBSSigIP, wEqFP, wPLFP,
nI, (ReportFI&RPT_TRANS)?1:0, LogFP,
ShortLowD, ShortHighD, LongLowD, LongHighD, CapitalD );
Done:
if ( wBSSigIP == (int *)0 ) free( (void *)wBSSigIP );
if ( wEqFP == (float *)0 ) free( (void *)wEqFP );
if ( wPLFP == (float *)0 ) free( (void *)wPLFP );
return( rcI );
}
/************************************************************************
* *
* Non-Linear Dynamical Systems *
* *
************************************************************************
*/
#ifdef NLDS
INPUT LISTSeries[] = { /* series,start,end */
ISTR( NFieldCA, IO_FLD ),
ISTR( NStrDateCA, IO_DTE|IO_OPT ),
ISTR( NEndDateCA, IO_DTE|IO_OPT ),
INUL
};
LIT LITDerivative[] = {
{ "no", 0 },
{ "yes", 1 },
{ 0 }
};
LIT LITPrintType[] = {
{ "formatted", PRT_TEXT },
{ "lotus", PRT_COMMA },
{ "excel", PRT_TAB },
{ 0 }
};
INPUT LISTPrinter[] = { /* filename,type */
ISTR( PrintFileCA, IO_FNM ),
IVAL( PrintTypeI, IO_INT|IO_LITONLY,FMT_INTS,LITPrintType ),
INUL
};
INPUT LISTGo[] = { /* startdim,enddim */
IVAL( StartDimI, IO_INT|IO_OPT,FMT_INTU,0 ),
IVAL( EndDimI, IO_INT|IO_OPT,FMT_INTU,0 ),
INUL
};
/* --- NLDSGoI() --- Start up procedure for NLDS
*/
int NLDSGoI( fp, WhatStrSP, cmTP, PromptSP )
FILE *fp; /* where to put output */
char *WhatStrSP; /* what it is we are doing */
CMD *cmTP; /* command table pointer */
char *PromptSP; /* prompt string */
{
if ( FieldsI <= 0 ) return( MustLoadDBI() );
fprintf( fp,
"* Entering Non-Linear Dynamical Systems Analysis by %s *\n",
WhatStrSP );
DoCommandsI( cmTP, PromptSP );
fprintf( fp,
"* Leaving Non-Linear Dynamical Systems Analysis by %s *\n",
WhatStrSP );
return( 0 );
}
/* --- CMDCkSeries() ---- Check series for valid syntax
* field.label[,date][,date]
* Field should have no offset assoicated with it
* dates are optional.
* NFldDataFP points to vector
* NFldStrXI is the offset into the vector to start at
* NFldLengthI is the number of items to use.
*/
int CMDCkSeries( cmdP, cntL, eFP ) /* Check for valid series & dates */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{ int rcI = 0; /* return code from parsing */
long dL; /* work long */
int wxI; /* work index */
NFieldFlagI = 0; /* not valid yet */
if ( FieldParseI( &NFieldT, NFieldCA ) )
return( MsgER( "Could not parse field" ) );
if ( (NFieldT.FFlagI & FD_FOUND) == 0 )
return( MsgER( "Field specified could not be found" ) );
if ( NFieldT.FOffI != 0 )
return( MsgER( "Offset is not permitted. Use date range instead" ) );
NFldDataFP = NFieldT.FFieldTP->FDataFP; /* point to the data */
NStrDateL = Date2BinL( NStrDateCA );
NEndDateL = Date2BinL( NEndDateCA );
if ( NStrDateL > NEndDateL )
{ dL = NStrDateL; NStrDateL = NEndDateL; NEndDateL = dL; }
NFldStrXI = -1;
for( wxI = 0; wxI < FVecI; wxI++ ) {
if ( NFldStrXI < 0 && FDateLP[wxI] >= NStrDateL )
NFldStrXI = wxI; /* start index */
if ( FDateLP[wxI] > NEndDateL ) break;
}
NFldLengthI = wxI - NFldStrXI;
if ( NFldStrXI < 0 || NFldLengthI <= 10 )
return( MsgER( "Too few items for analysis" ) );
Done:
if ( rcI == 0 ) NFieldFlagI = 1;
return( rcI ); /* return code */
}
/* --- CMDPrinter() --- Copy printer file name to type file name
*/
int CMDPrinter( cmdP, cntL, eFP ) /* copy printer file to type file */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{ FILE *fp; /* new output file */
char *OpenModeSP; /* open mode */
OpenModeSP = PrintTypeI==PRT_TEXT? "a":"w";
if ( (fp = fopen( PrintFileCA, OpenModeSP )) == (FILE *)0 )
return( MsgER( "Could not open printer output file" ) );
if ( PrintFileFP ) fclose( PrintFileFP );
if ( PrintTypeI == PRT_TEXT ) {
fputs( "\n\f", fp );
fflush( fp );
}
PrintFileFP = fp;
PrintFilePosL = ftell( fp );
strcpy( TypeFileCA, PrintFileCA );
return( 0 );
}
int CheckPointPrinter() /* check-point printer output */
{
if ( PrintFileFP ) {
fflush( PrintFileFP );
fclose( PrintFileFP );
PrintFileFP = fopen( PrintFileCA, "a" );
return( PrintFileFP? 1:(-1) );
}
return( 0 );
}
int CMDTypeFile( cmdP, cntL, eFP ) /* copy printer file to type file */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{ FILE *fp; /* input file */
int c; /* work char */
int scrcntI; /* screen count */
CheckPointPrinter();
if ( (fp = fopen( TypeFileCA, "r" )) == (FILE *)0 )
return( MsgER( "Could not open input file to type" ) );
if ( strcmp( TypeFileCA, PrintFileCA ) == 0 )
fseek( fp, PrintFilePosL, 0 ); /* skip to new stuff */
fprintf( stdout, "-- Displaying file <%s> --\n", TypeFileCA );
for( c=0, scrcntI = 21;;) {
c = fgetc( fp );
if ( feof(fp) || ferror(fp) ) break;
fputc( c, stdout );
if ( c == '\n' ) {
if ( --scrcntI <= 0 ) {
scrcntI = 22; /* pause at end of screen */
fputs( "\rPress Space to Continue", stdout );
fflush( stdout );
while( getch() != ' ' )
;
fputs( "\r \r", stdout );
}
}
}
if ( c != '\n' ) fputc( '\n', stdout );
fflush( stdout );
fclose( fp );
return( 0 );
}
int CMDNQuit( cmdP, cntL, eFP ) /* Quit NLDS section */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{
if ( PrintFileFP != (FILE *)0 ) fclose( PrintFileFP );
PrintFileFP = (FILE *)0;
QuitI = 1;
return( 0 );
}
int CMDGoHurst( cmdP, cntL, eFP ) /* Hurst Coefficient Analysis */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{ unsigned vlenU; /* length of each vector */
int rcI=0; /* return code */
float *hurstFP, *nFP, *rsFP, *lognFP, *logrsFP;
FILE *fp; /* output file pointer */
char *fmtSP; /* format for printfs */
char *hdrSP; /* format for header */
int wxI; /* work index */
int PrtMdeI; /* local print mode */
if ( !NFieldFlagI )
return( MsgER( "Must specify series to analyze" ) );
if ( IterationsI < 5 ) IterationsI = 5;
vlenU = ((unsigned)IterationsI+2)*sizeof(*hurstFP);
hurstFP = (float *)malloc( 5*vlenU );
nFP = hurstFP + IterationsI;
rsFP = nFP + IterationsI;
lognFP = rsFP + IterationsI;
logrsFP = lognFP + IterationsI;
HurstI( hurstFP, nFP, rsFP, lognFP, logrsFP,
&NFldDataFP[NFldStrXI], NFldLengthI,
StartWinI, DeltaWinI, IterationsI, DerivativeI );
if ( PrintFileFP ) {
fp = PrintFileFP;
PrtMdeI = PrintTypeI;
} else {
fp = stdout;
PrtMdeI = PRT_TEXT;
}
switch( PrtMdeI ) {
case PRT_TEXT: default:
hdrSP = " %7s %7s %8s %7s %7s\n";
fmtSP = " %7.3f %7.0f %8.3f %7.3f %7.3f\n";
break;
case PRT_COMMA:
hdrSP = "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n";
fmtSP = "%.3f,%.0f,%.3f,%.3f,%.3f\n";
break;
case PRT_TAB:
hdrSP = "%s\t%s\t%s\t%s\t%s\n";
fmtSP = "%.3f\t%.0f\t%.3f\t%.3f\t%.3f\n";
break;
}
if ( PrintTypeI == PRT_TEXT ) fprintf( fp, "\n" );
fprintf( fp, hdrSP, "hurst", "n", "rs", "log(n)", "log(rs)" );
for( wxI = 0; wxI < IterationsI; wxI++ )
fprintf( fp, fmtSP,
hurstFP[wxI], nFP[wxI], rsFP[wxI],
lognFP[wxI], logrsFP[wxI] );
if ( PrintTypeI == PRT_TEXT ) fprintf( fp, "\n" );
CheckPointPrinter();
Done:
if ( hurstFP ) free( (void *)hurstFP );
return( rcI );
}
CMD cmdlHURST[] = {
{ "series", "Data series to analyze",
CMDCkSeries, ILIST( LISTSeries, IO_DSP ) },
{ "startwindowsize", "Initial window size",
0, IVAL( StartWinI, IO_INT,FMT_INTU, 0 ) },
{ "deltawindowsize", "Change in window size",
0, IVAL( DeltaWinI, IO_INT,FMT_INTU, 0 ) },
{ "iterations", "Number of iterations to perform",
0, IVAL( IterationsI, IO_INT,FMT_INTU, 0 ) },
{ "derivative", "Use derivative of series",
0, IVAL( DerivativeI, IO_INT|IO_LITONLY,FMT_INTS,LITDerivative ) },
{ "dictionary", "Display dictionary",
CMDDict, IACTR0 },
{ "printfile", "Printed output data file",
CMDPrinter, ILIST( LISTPrinter, IO_DSP ) },
{ "type", "Type a file to console",
CMDTypeFile, ISTR( TypeFileCA, IO_FNM|IO_OPT ) },
{ "go", "Hurst coefficient analysis",
CMDGoHurst, IACTR0 },
{ "quit", "Return to main menu",
CMDNQuit, IACTR0 },
{ 0 }
};
int CMDHurst( cmdP, cntL, eFP ) /* enter Hurst Coefficient section */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{ return( NLDSGoI( eFP, "Hurst Exponent", &cmdlHURST[0], "Hurst" ) );
}
int CMDGoCorDim( cmdP, cntL, eFP ) /* compute correlation dimension */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{ unsigned vlenU; /* length of each vector */
int rcI=0; /* return code */
float *rFP, *crFP, *logrFP, *logcrFP, *regFP;
FILE *fp; /* output file pointer */
char *fmtSP; /* format for printfs */
char *hdrSP; /* format for header */
char *sp; /* work string pointer */
int wxI; /* work index */
int DimI; /* current dimension */
int PrtMdeI; /* printer mode */
if ( !NFieldFlagI )
return( MsgER( "Must specify series to analyze" ) );
if ( cntL < 2 ) {
switch( cntL ) {
case 0: StartDimI = EndDimI = EvolveI; break;
case 1: EndDimI = EvolveI; break;
}
}
if ( StartDimI > EndDimI )
{ DimI = StartDimI; StartDimI = EndDimI; EndDimI = DimI; }
if ( IterationsI < 10 ) IterationsI = 10;
vlenU = ((unsigned)IterationsI+2)*sizeof(float);
rFP = (float *)malloc( 5*vlenU );
if ( rFP == (float *)0 ) {
rcI = -1;
goto Done;
}
crFP = rFP + IterationsI;
logrFP = crFP + IterationsI;
logcrFP = logrFP + IterationsI;
regFP = logcrFP + IterationsI;
if ( PrintFileFP ) {
fp = PrintFileFP;
PrtMdeI = PrintTypeI;
} else {
fp = stdout;
PrtMdeI = PRT_TEXT;
}
for( DimI = StartDimI; DimI <= EndDimI; DimI++ ) {
sp = (PrtMdeI == PRT_COMMA? "\"":"");
fprintf( fp,
"%sCorrDim: Embedding Dim=%d for <%s> from <%s> to <%s>\n%s",
sp,DimI,NFieldCA,NStrDateCA,NEndDateCA,sp );
CheckPointPrinter();
if ( PrintFileFP )
fprintf( stderr,
"Embedding Dim=%d for <%s> from <%s> to <%s>\n",
DimI,NFieldCA,NStrDateCA,NEndDateCA );
#ifdef CORRDIMORG
CorrDimI( rFP, crFP, logrFP, logcrFP, regFP,
&NFldDataFP[NFldStrXI], NFldLengthI,
DimI, tauI, dtD, radiusD, IterationsI );
#else
CorrDim2I( rFP, crFP, logrFP, logcrFP, regFP,
&NFldDataFP[NFldStrXI], NFldLengthI,
DimI, tauI, IterationsI );
#endif
switch( PrtMdeI ) {
case PRT_TEXT: default:
hdrSP = " %7s %7s %8s %7s %7s\n";
fmtSP = " %7.3f %7.3f %8.3f %7.3f %7.3f\n";
break;
case PRT_COMMA:
hdrSP = "\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n";
fmtSP = "%.3f,%.3f,%.3f,%.3f,%.3f\n";
break;
case PRT_TAB:
hdrSP = "%s\t%s\t%s\t%s\t%s\n";
fmtSP = "%.3f\t%.3f\t%.3f\t%.3f\t%.3f\n";
break;
}
if ( PrintTypeI == PRT_TEXT ) fprintf( fp, "\n" );
fprintf( fp, hdrSP, "reg cor", "r", "cd", "log(r)", "log(cd)" );
for( wxI = 0; wxI < IterationsI; wxI++ )
fprintf( fp, fmtSP,
regFP[wxI], rFP[wxI], crFP[wxI],
logrFP[wxI], logcrFP[wxI] );
if ( PrintTypeI == PRT_TEXT ) fprintf( fp, "\n" );
CheckPointPrinter();
}
Done:
if ( rFP ) free( (void *)rFP );
return( rcI );
}
CMD cmdlCORDIM[] = {
{ "series", "Data series to analyze",
CMDCkSeries, ILIST( LISTSeries, IO_DSP ) },
{ "embedding", "Embedding dimension",
0, IVAL( EmbeddingI, IO_INT,FMT_INTU,0 ) },
{ "tau", "Lag for re-creating phase space",
0, IVAL( tauI, IO_INT,FMT_INTU,0 ) },
#ifdef CORRDIMORG
{ "radius", "initial radius",
0, IVAL( radiusD, IO_FLT,FMT_FLT3, 0 ) },
{ "deltaradius", "change in radius",
0, IVAL( dtD, IO_FLT,FMT_FLT3, 0 ) },
#endif
{ "iterations", "Number of iterations to perform",
0, IVAL( IterationsI, IO_INT,FMT_INTU, 0 ) },
{ "dictionary", "Display dictionary",
CMDDict, IACTR0 },
{ "printfile", "Printed output data file",
CMDPrinter, ILIST( LISTPrinter, IO_DSP ) },
{ "type", "Type a file to console",
CMDTypeFile, ISTR( TypeFileCA, IO_FNM|IO_OPT ) },
{ "go", "Correlation Dimension analysis",
CMDGoCorDim, ILIST( LISTGo, IO_DSP ) },
{ "quit", "Return to main menu",
CMDNQuit, IACTR0 },
{ 0 }
};
int CMDCorDim( cmdP, cntL, eFP ) /* enter Correlation Dimension section */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{ return( NLDSGoI( eFP, "Correlation Dimension", &cmdlCORDIM[0],"CorrDim" ) );
}
int CMDGoLyapunov( cmdP, cntL, eFP ) /* compute lyapunov exponent */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{ unsigned vlenU; /* length of each vector */
int rcI=0; /* return code */
float *zlyapFP, *EvolveItFP, *diFP, *DFFP, *regFP;
FILE *fp; /* output file pointer */
char *fmtSP; /* format for printfs */
char *hdrSP; /* format for header */
char *sp; /* work char pointer */
int wxI; /* work index */
int DimI; /* current dimension */
int PrtMdeI; /* local print mode */
int ItersI; /* # of actual interations */
if ( !NFieldFlagI )
return( MsgER( "Must specify series to analyze" ) );
if ( cntL < 2 ) {
switch( cntL ) {
case 0: StartDimI = EndDimI = EmbeddingI; break;
case 1: EndDimI = EmbeddingI; break;
}
}
if ( StartDimI > EndDimI )
{ DimI = StartDimI; StartDimI = EndDimI; EndDimI = DimI; }
vlenU = ((unsigned)NFldLengthI+2)*sizeof(float);
zlyapFP = (float *)malloc( 4*vlenU );
if ( zlyapFP == (float *)0 ) {
rcI = -1;
goto Done;
}
EvolveItFP = zlyapFP + NFldLengthI;
diFP = EvolveItFP + NFldLengthI;
DFFP = diFP + NFldLengthI;
if ( PrintFileFP ) {
fp = PrintFileFP;
PrtMdeI = PrintTypeI;
} else {
fp = stdout;
PrtMdeI = PRT_TEXT;
}
for( DimI = StartDimI; DimI <= EndDimI; DimI++ ) {
sp = (PrtMdeI == PRT_COMMA? "\"":"");
fprintf( fp,
"%sLyapunov: Embedding Dim=%d for <%s> from <%s> to <%s>\n%s",
sp,DimI,NFieldCA,NStrDateCA,NEndDateCA,sp );
CheckPointPrinter();
if ( PrintFileFP )
fprintf( stderr,
"Embedding Dim=%d for <%s> from <%s> to <%s>\n",
DimI,NFieldCA,NStrDateCA,NEndDateCA );
ItersI = LyapunovI( zlyapFP, EvolveItFP, diFP, DFFP,
&NFldDataFP[NFldStrXI], NFldLengthI,
DimI, tauI, dtD, NMaxScaleD, NMinScaleD,
EvolveI, LagMinimumI );
switch( PrintTypeI ) {
case PRT_TEXT: default:
hdrSP = " %7s %8s %7s %7s\n";
fmtSP = " %7.3f %8.0f %7.3f %7.3f\n";
break;
case PRT_COMMA:
hdrSP = "\"%s\",\"%s\",\"%s\",\"%s\"\n";
fmtSP = "%.3f,%.0f,%.3f,%.3f\n";
break;
case PRT_TAB:
hdrSP = "%s\t%s\t%s\t%s\n";
fmtSP = "%.3f\t%.0f\t%.3f\t%.3f\n";
break;
}
if ( PrintTypeI == PRT_TEXT ) fprintf( fp, "\n" );
fprintf( fp, hdrSP, "zlyap", "Evolve", "di", "DF" );
for( wxI = 0; wxI < ItersI; wxI++ )
fprintf( fp, fmtSP,
zlyapFP[wxI], EvolveItFP[wxI],
diFP[wxI], DFFP[wxI] );
if ( PrintTypeI == PRT_TEXT ) fprintf( fp, "\n" );
CheckPointPrinter();
}
Done:
if ( zlyapFP ) free( (void *)zlyapFP );
return( rcI );
}
CMD cmdlLYAP[] = {
{ "series", "Data series to analyze",
CMDCkSeries, ILIST( LISTSeries, IO_DSP ) },
{ "embedding", "Embedding dimension",
0, IVAL( EmbeddingI, IO_INT,FMT_INTU,0 ) },
{ "tau", "Lag for re-creating phase space",
0, IVAL( tauI, IO_INT,FMT_INTU,0 ) },
{ "minscale", "Minimum radius",
0, IVAL( NMinScaleD, IO_FLT,FMT_FLT3,0 ) },
{ "maxscale", "Maximum radius",
0, IVAL( NMaxScaleD, IO_FLT,FMT_FLT3,0 ) },
{ "evolve", "Number of time steps per evolution",
0, IVAL( EvolveI, IO_INT,FMT_INTU,0 ) },
{ "lagminimum", "Minimum lag between points",
0, IVAL( LagMinimumI, IO_INT,FMT_INTU,0 ) },
{ "dictionary", "Display dictionary",
CMDDict, IACTR0 },
{ "printfile", "Printed output data file",
CMDPrinter, ILIST( LISTPrinter, IO_DSP ) },
{ "type", "Type a file to console",
CMDTypeFile, ISTR( TypeFileCA, IO_FNM|IO_OPT ) },
{ "go", "Lyapunov Exponent analysis",
CMDGoLyapunov, ILIST( LISTGo, IO_DSP ) },
{ "quit", "Return to main menu",
CMDNQuit, IACTR0 },
{ 0 }
};
int CMDLyapunov( cmdP, cntL, eFP ) /* enter Lyapunov Exponent section */
CMD *cmdP; /* pointer to command table */
long cntL; /* # of items converted */
FILE *eFP; /* error file pointer */
{ return( NLDSGoI( eFP, "Lyapunov Exponent", &cmdlLYAP[0], "Lyapunov" ));
}
#endif
/* --- Main Command Interpreter Table --- */
CMD ct[] = {
{ "load", "Load data-base to memory",
CMDLoad, ILIST( LISTLoad, IO_DSP ) },
{ "interpolate", "Interpolate zero values",
CMDInterp, IACTR0 },
{ "scale", "Scale data to min,max range",
CMDScale, ILIST( LISTScale, IO_DSP ) },
{ "transform", "Write out transforms",
CMDTrans, ILIST( LISTTrans, IO_DSP ) },
{ "saveall", "Save data-base",
CMDSave, ILIST( LISTSave, IO_DSP ) },
{ "log", "Log actions to a file",
CMDLog, ISTR( LogFile, IO_DSP|IO_FNM ) },
{ "dictionary", "Display dictionary",
CMDDict, IACTR0 },
{ "quit", "Terminate this program",
CMDQuit, IACTR0 },
/* --- Transformation commands --- */
{ "movingaverage", "Moving average",
CMDMovAvg, ILIST( LISTFldDay, IO_DSP ) },
{ "rsi", "Relative strength indicator",
CMDRSI, ILIST( LISTFldDay, IO_DSP ) },
{ "stochastic", "Stochastic with smoothing",
CMDStoch, ILIST( LISTStoch, IO_DSP ) },
{ "volatility", "Volatility",
CMDVol, ILIST( LISTFldDay, IO_DSP ) },
{ "highlow", "Volatility using high,low series",
CMDHLVol, ILIST( LISTFFDay, IO_DSP ) },
{ "slope", "Slope between two series",
CMDSlope, ILIST( LISTOFFDay, IO_DSP ) },
{ "intercept", "Intercept betweem two seroes",
CMDInter, ILIST( LISTOFFDay, IO_DSP ) },
{ "rollingcorrelation","Rolling correlation",
CMDCorr, ILIST( LISTFFDay, IO_DSP ) },
{ "raw", "Copy a column of data",
CMDRaw, ISTR( XFieldCA, IO_FLD|IO_DSP ) },
/* --- Analysis Section --- */
{ "network", "Load the neural net output",
CMDNet, ILIST( LISTNet, IO_DSP ) },
{ "short", "Net min,max for short position",
0, ILIST( LISTShort, IO_DSP ) },
{ "long", "Net min,max for long position",
0, ILIST( LISTLong, IO_DSP ) },
{ "capital", "Initial capital for analysis",
0, IVAL( CapitalD, IO_FLT,FMT_FLT0, 0 ) },
{ "price", "Field for buy/sell price",
CMDPrice, ISTR( PrFldCP, IO_DSP|IO_FLD ) },
{ "report", "Identify options for report", 0,
IVAL( ReportFI, IO_INT|IO_LITONLY,FMT_INTS,LITReport ) },
{ "analyze", "Analyze network data",
CMDAnal, ILIST( LISTAnal, IO_DSP ) },
/* --- Non-Linear Dynamical Systems --- */
#ifdef NLDS
{ "hurst", "NLDS: Hurst exponent",
CMDHurst, IACTR0 },
{ "correlationdime", "NLDS: Correlation Dimension",
CMDCorDim, IACTR0 },
{ "lyapunov", "NLDS: Largest Lyapunov Exponent",
CMDLyapunov, IACTR0 },
#endif
{ 0 }
};
int MsgER( buf )
char *buf;
{
fputs( buf, stderr );
fputs( "\n", stderr );
if ( LogFP != (FILE *)0 ) {
fputs( buf, LogFP );
fputs( "\n", LogFP );
}
return( -1 );
}
char *HelpSPP[] = {
"Use: ? Make a list of all current variable values\n",
" ?? List syntax of all variables AND commands\n",
" ?v Print the current value of all variables staring with v\n",
" var? Prints the syntax for this if unique, otherwise a list\n",
" of possible matches\n",
" command executes a command.\n",
" var=val assigns a value to a variable\n",
" var val ditto\n",
"\n",
" Commands and Variables may be abbreviated to the fewest characters\n",
" which provide for unique identification.\n",
0
};
main(ac,av)
int ac; /* arg counter */
char *av[]; /* arg pointer */
{ int wxI; /* work index */
fputs(
"Copyright (c) 1992, High-Tech Communications. All rights reserved.\n",
stdout );
fputs(
"103 Buckskin Court, Sewickley, PA 15143, USA.\n",
stdout );
fputs(
"FAX: 412-741-6094 TEL: 412-741-7699\n", stdout );
for( wxI = 0; HelpSPP[wxI] != (char *)0; wxI++ )
fputs( HelpSPP[wxI], stdout );
fflush( stdout );
DoCommandsI( &ct[0], "Command" );
exit( 0 );
}